<?php
if(isset($_GET['j']) && $_GET['j']!="") {
	$j = $_GET['j'];
	$kd_jaksa = $j;
	$dt_jaksa = mysql_fetch_array(mysql_query("
	SELECT * FROM t_p16_jaksa a
	LEFT JOIN t_pegawai b ON a.kd_pegawai = b.kd_pegawai
	LEFT JOIN r_pangkat c ON b.kd_pangkat = c.kd_pangkat
	WHERE kd_perkara ='".KD_PERKARA."' AND a.kd_pegawai ='".$_GET['j']."'
	"));
} else {
	$j = "";
	$dt_jaksa = mysql_fetch_array(mysql_query("
	SELECT * FROM t_p16_jaksa a
	LEFT JOIN t_pegawai b ON a.kd_pegawai = b.kd_pegawai
	LEFT JOIN r_pangkat c ON b.kd_pangkat = c.kd_pangkat
	WHERE kd_perkara ='".KD_PERKARA."'
	"));
	$kd_jaksa = $dt_jaksa['kd_pegawai'];	
//	$kd_jaksa = $_POST['txt_jaksa'];
}

$jaksa_ada = data_tersedia('t_p16_jaksa',KD_PERKARA);
$jaksa_terpakai = mysql_fetch_array(mysql_query("
	SELECT GROUP_CONCAT(kd_pegawai) 
	FROM t_p16_jaksa a WHERE a.kd_perkara ='".KD_PERKARA."'"));

if($jaksa_terpakai[0]!="") {
	//$tx_batas ="AND kd_pegawai NOT IN (".$jaksa_terpakai[0].")";
	$tx_batas ="AND a.kd_pegawai NOT IN ($jaksa_terpakai[0])";
} else {
	$tx_batas ="";
}


if($jaksa_ada && $j!="tambah") {
//if(($jaksa_ada && $j!="tambah")|| ($_POST['txt_jaksa']==$dt_jaksa['kd_pegawai'])) {
	$jaksa = $dt_jaksa['kd_pegawai'];
	$nama = $dt_jaksa['nm_lengkap'];
	$pangkat = $dt_jaksa['nm_pangkat'];
	$nip = $dt_jaksa['nip'];
	$jabatan = "JAKSA PENUNTUT UMUM";
} elseif(!$jaksa_ada || $j=="tambah") {
	$nama = "";
	$pangkat = "";
	$nip = "";
	$jabatan = "";
}


$q_jaksa = mysql_query("
	SELECT * FROM t_p16_jaksa a
	LEFT JOIN t_pegawai b ON a.kd_pegawai = b.kd_pegawai
	LEFT JOIN r_pangkat c ON b.kd_pangkat = c.kd_pangkat
	WHERE kd_perkara ='".KD_PERKARA."'
");


?>

<form id="da-form-p16" class="da-form" method="post" action="modul/perkara/perkara.proses.php">
<div class="da-form-inline">
	<div class="da-form-row">
		<label class="da-form-label">Nomor Surat</label>
		<div class="da-form-item">
		<?php if(data_tersedia('t_p16',KD_PERKARA)) {
			$dt = mysql_fetch_array(mysql_query("SELECT * FROM t_p16 WHERE kd_perkara='".KD_PERKARA."'"));
			if(LEVEL=="superadmin" || LEVEL=="admin") {
				echo '<input type="text" name="no_p16" value="'.$dt['no_surat'].'/0.5.10.3/'.$dt_spdp['jns_pidana'].konversi_tanggal('/m/Y',$dt['tgl_dikeluarkan']).'">';
			} else {
				echo 'PRINT- '.$dt['no_surat'].'/0.5.10.3/'.$dt_spdp['jns_pidana'].konversi_tanggal('/m/Y',$dt['tgl_dikeluarkan']);
			}
		} else {
			if(LEVEL=="superadmin" || LEVEL=="admin") {
				echo '<input type="text" name="no_p16">';
			} else {
				echo 'PRINT- '.p16_register($dt_spdp['kd_pidana']).'/0.5.10.3/'.$dt_spdp['jns_pidana'].date('/m/Y');
			}
		} 
		?>
		</div>
	</div>
	<div class="da-form-row">
		<label class="da-form-label">Tanggal Surat</label>
		<div class="da-form-item">
		<?php if(data_tersedia('t_p16',KD_PERKARA)) {
			$dt = mysql_fetch_array(mysql_query("SELECT * FROM t_p16 WHERE kd_perkara='".KD_PERKARA."'"));
			if(LEVEL=="superadmin" || LEVEL=="admin") {
				echo '<input type="text"  id="da-tgl-p16-dikeluarkan"  name="tgl_dikeluarkan" value="'.konversi_tanggal('d-m-Y',$dt['tgl_dikeluarkan']).'">';
			} else {
				echo konversi_tanggal('d/m/Y',$dt['tgl_dikeluarkan']);
			}
		} else { ?>
			<input type="text"  id="da-tgl-p16-dikeluarkan" name="tgl_dikeluarkan">
		<?php } ?>
		</div>
	</div>
	<fieldset class="da-form-inline">
		<legend>Jaksa Penuntut Umum</legend>
	</fieldset>
	<?php if($jaksa_ada) { ?>
	<div class="da-panel-toolbar">
		<div class="btn-toolbar">
			<div class="btn-group">
			<?php 						
				$i = 1;
				while($dt=mysql_fetch_array($q_jaksa)) { 
					if($i==1) {$d=  true;} else {$d = "";}
			?>
				<a <?php tab_aktif($j,$dt['kd_pegawai'],PAGE_ID.'&p=p16&j='.$dt['kd_pegawai'],$d)?>>Jaksa <?php echo $i ?></a>
			<?php 
				$i++; } 

				if($t!="tambah") { 
				if(LEVEL=="superadmin" || LEVEL=="kasipidum") {
			?>
				<a href="?kd=<?php echo KD_PERKARA?>&p=p16&j=tambah" class="btn"><i class="icol-add"></i> Tambah</a>
			<?php }} ?>
			</div>
		</div>
	</div>
	<?php } ?>

	
	<table class="da-table da-detail-view no-border">
		<tbody>
		
		<tr>
			<th>Nama Lengkap</th>
			<td>
				<?php if(LEVEL!="superadmin" && LEVEL!="kasipidum") { echo $nama; } else { ?>				
				<select class="select2 span6" name="kd_jaksa" id="cb_jaksa" onload="buka();">
				
				<?php //if($jaksa_ada && $j!="tambah") { ?>
				<?php //if($jaksa_ada) { ?>				
					<!--<option value="<?php echo $jaksa ?>"><?php echo $nama ?></option>-->
				<?php
					//}					
					$q = mysql_query("	select a.kd_pegawai,a.nip,a.nm_lengkap, 
										b.kd_jabatan,b.nm_jabatan, c.nm_pangkat, count(a.kd_pegawai) as jlh  
										from t_pegawai a inner join r_jabatan b on a.kd_jabatan = b.kd_jabatan 
										inner join r_pangkat c on c.kd_pangkat = a.kd_pangkat 
										where b.kd_jabatan IN(6,7,8,9) group by a.kd_pegawai;");
					while($dt = mysql_fetch_array($q)) {
					$status = ($jaksa==$dt['kd_pegawai']) ? 'selected' :'';
				?>
					<option value="<?php echo $dt['kd_pegawai'] ?>" <?php echo $status ?>><?php echo $dt['nm_lengkap'].", ".jpu_statistik($dt['kd_pegawai'], 't')." Perkara" ?></option>
				<?php } } ?>
				</select>
				<input type="hidden" name="txt_jaksa" id="txt_jaksa" value="<?php echo $dt_jaksa['kd_pegawai']; ?>">
			</td>
		</tr>

		<?php	/* 
			if(($jaksa_ada) && ($j==$dt_jaksa['kd_pegawai'])) { 
			$query 	= "select a.kd_pegawai,a.nip,a.nm_lengkap, b.kd_jabatan, b.nm_jabatan, c.nm_pangkat, count(d.kd_pegawai) as jlh from t_pegawai a
						inner join r_jabatan b on a.kd_jabatan = b.kd_jabatan
						inner join r_pangkat c on c.kd_pangkat = a.kd_pangkat
						left join t_p16_jaksa d on d.kd_pegawai = a.kd_pegawai
						where b.kd_jabatan IN(6,7,8,9) and a.kd_pegawai ='$dt_jaksa[kd_pegawai]' group by d.kd_pegawai";
			$result	= mysql_query($query);
			$baris	= mysql_num_rows($result);
	
			while($row=mysql_fetch_array($result)){
				$jpangkat = $row['nm_pangkat'];
				$jnip	 = $row['nip'];
				$jjabatan = $row['nm_jabatan'];
				$jperkara = $row['jlh'];
			}
		*/
		?>				
		<!--<tr>
			<th>Pangkat1</th>
			<td><?php echo $jpangkat;?></td>
		</tr>
		<tr>
			<th>NIP</th>
			<td><?php echo $jnip; ?></td>
		</tr>
		<tr>
			<th>Jabatan</th>
			<td><?php echo $jjabatan; ?></td>
		</tr>
		<tr>
			<th>Beban Perkara</th>
			<td><?php echo $jperkara." Perkara"; ?></td>
		</tr>
		</div>-->
		<?php //}?>
		
		<div id="isi">			
		
		</div>		
		
		</tbody>
	</table>

	
	<?php if(LEVEL=="superadmin" || LEVEL=="kasipidum") { ?>
	<div class="da-panel-toolbar">
		<div class="btn-toolbar">
			<div class="btn-group">
			<?php if(($jaksa_ada && $j=="") || ($j!="" && $j!="tambah")) { ?>
				
				<button  id="ubah-jaksa" class="btn"><i class="icol-disk"></i> Ubah</button>
				<a href="functions/crud/perkara.php?kd=<?php echo KD_PERKARA?>&jaksa=<?php echo $kd_jaksa ?>" class="btn">
				<i class="icol-cross"></i> Hapus
				</a>
			<?php } else { ?>
				<button  id="tambah-jaksa" class="btn"><i class="icol-disk"></i> Simpan</button>
			<?php } ?>
			</div>
		</div>
	</div>
	<?php } ?>
	</div>
	<div class="btn-row">
		<?php if(LEVEL=="superadmin" || LEVEL=="admin" || LEVEL=="kasipidum") { ?>
			<button id="tambah-p16" class="btn"><i class="icol-disk"></i> Simpan</button>
		<?php } ?>
		<?php if(LEVEL=="superadmin" || LEVEL=="pratut") { if($jaksa_ada) { ?>
			<a href="#" id="p16-dialog" class="btn"><i class="icol-printer"></i> Cetak</a>
		<?php }else { ?>
			<a href="#" class="btn disabled"><i class="icol-printer"></i> Cetak</a>
		<?php }}?>
		<?php if(LEVEL=="jaksa"){ ?>
			<a href="#" id="p16-dialog-lihat" class="btn"><i class="icol-find"></i> Lihat</a>
		<?php } ?>
		<input id="mode-input" type="hidden" name="p16" value=""/>
		<input type="hidden" name="kd" value="<?php echo KD_PERKARA ?>" />
		<input type="hidden" name="kd_pegawai" value="<?php echo ID_PEGAWAI ?>" />
		<input type="hidden" name="kd_jaksa_2" value="<?php echo $kd_jaksa ?>" />
	</div>
</form>

<div id="p16-dialog-div" style="display:none;">
	<p id="berkas"></p>
</div>

<div id="p16-dialog-lihat-div" style="display:none;">
	<p id="berkas-lihat"></p>
</div>
